<template>
  <div class="box1">
    <img
      src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u3.png"
      alt=""
      class="img1"
    >
    <img
      src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u4.png"
      alt=""
      class="img2"
    >
    <img
      src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u5.png"
      alt=""
      class="img3"
    >
    <div class="zhuti">
      <img
        src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u25.png"
        alt=""
        class="img4"
      >
      <div class="form">
        <h2> <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u24.png">电商后台管理</h2>
        <el-form ref="loginForm" :model="loginForm" :rules="formRules">
          <el-form-item prop="mobile">
            <el-input v-model="loginForm.mobile" placeholder="请输入用户名" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" placeholder="请输入密码" show-password />
          </el-form-item>
          <el-form-item prop="captcha">
            <el-input v-model="loginForm.captcha" placeholder="请输入验证码"><template slot="append"><span @click="captchaAdd">{{ cap }}</span></template></el-input>
          </el-form-item>
          <el-form-item prop="isAgree">
            <el-checkbox v-model="loginForm.isAgree">用户平台协议</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="loginClick">登录</el-button>
          </el-form-item>
        </el-form>
      </div>

    </div>
  </div>
</template>

<script>
export default {
  name: 'Login1',
  data() {
    return {
      loginForm: {
        mobile: process.env.NODE_ENV === 'development' ? '13800000001' : '',
        password: process.env.NODE_ENV === 'development' ? 'hm#qd@23!' : '',
        isAgree: process.env.NODE_ENV === 'development',
        captcha: ''
      },
      cap: '',
      formRules: {
        mobile: [
          { required: true, message: '不能为空', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 16, message: '密码长度为6-16位之间', trigger: 'blur' }
        ],
        isAgree: [
          { validator: (rule, value, callback) => {
            value ? callback() : callback(new Error('请勾选用户协议'))
          }
          }
        ],
        captcha: [
          { validator: (rule, value, callback) => {
            if (value === '') {
              callback(new Error('请输入验证码'))
            } else if (value !== this.cap) {
              callback(new Error('验证码错误'))
            } else {
              callback()
            }
          }, trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
    return this.captchaAdd()
  },
  methods: {
    captchaAdd() {
      // this.cap = ''
      for (let i = 0; i < 4; i++) {
        const a = Math.floor(Math.random() * 10)
        this.cap += a
      }
    },
    loginClick() {
      this.$refs.loginForm.validate((isOK) => {
        if (isOK) {
          this.$store.dispatch('user/loginAction', this.loginForm)
        }
      })
    }
  }
}
</script>

<style lang="scss">
.box1 {
  position: relative;
  height: 100%;
  background-image: linear-gradient(#3fccfd, #996cfb);
  overflow: hidden;
    .img1{
      position: absolute;
      top: 50px;
      right: 400px;
    }
    .img2{
      position: absolute;
      top: -100px;
      left: -100px;
    }
    .img3{
      position: absolute;
      bottom: 50px;
      right: 50px;
    }
    .zhuti {
      display: flex;
      position: absolute;
      justify-content: space-between;
      top: 50%;
      left: 50%;

      transform: translate(-50%,-50%);
      height: 450px;
      width: 1000px;
      .img4 {
        width: 450px;
        height: 450px;
      }

      .form {
        border-radius: 20px;
        width: 450px;
        height: 450px;
        background-color: #fff;

        h2{
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 30px;
          img{
            margin-right:10px ;
          }
        }
        .el-form{
          margin-left: 50px;
          width: 350px;
        }
        .el-input__inner {
          height: 50px;
        }
        .el-input-group__append {
          color: red;
          letter-spacing: 3px;
        }
        .el-button {
          width: 350px;
          height: 50px;
          border-radius: 25px;
        }

      }
    }
}
</style>
